<template>
  <div class="dialog-box">
    <el-dialog
      class="dialog"
      title="修改用户信息"
      :visible.sync="dialogFormVisible"
      width="400px"
    >
      <el-form :model="form" :rules="rules">
        <el-form-item
          label="用户昵称"
          :label-width="formLabelWidth"
          :value="form.nickname"
          prop="nickname"
        >
          <el-input v-model="form.nickname" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="cancel()">取 消</el-button>
        <el-button type="primary" @click.native="submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { Bus } from "../../Bus";
import { changeusername } from "../../api/datas";
export default {
  data() {
    return {
      dialogFormVisible: true,
      form: {
        nickname: "",
        type: [],
      },
      formLabelWidth: "80px",
      isShowDialog2: false,
      rules: {
        nickname: [
          { required: true, message: "请输入用户昵称", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submit() {
      this.dialogFormVisible = false;
      Bus.$emit("isShowDialog2", this.isShowDialog2);
      if (this.form.nickname) {
        changeusername({
          id: this.$store.state.usermsg.id,
          nickname: this.form.nickname,
        }).then((res) => {
          console.log(res);
        });
      }
    },
    cancel() {
      this.dialogFormVisible = false;
      Bus.$emit("isShowDialog2", this.isShowDialog2);
    },
  },
};
</script>